package com.lilosoft.business.task;

import com.github.pagehelper.PageInfo;
import com.lilosoft.business.cga.models.CgaCase;
import com.lilosoft.business.cga.service.CgaCaseService;
import com.lilosoft.business.precity.models.DownDataError;
import com.lilosoft.business.precity.models.DownDataErrorExample;
import com.lilosoft.business.precity.service.DownDataErrorService;
import com.lilosoft.business.precity.service.UpDataReconciliationService;
import com.lilosoft.core.utils.commons.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 小峰
 * Date: 2019-12-17
 * Time: 20:05
 */
@Component
public class DeleErrorInfoTask {
    @Autowired
    private DownDataErrorService downDataErrorService;
    @Autowired
    private CgaCaseService cgaCaseService;
    @Autowired
    private SynchronousPreCity synchronousPreCity;
    @Autowired
    private UpDataReconciliationService upDataReconciliationService;


    public void invokeDelete() {
        int countPage = 2;
        long countTotal = 0;
        PageInfo<DownDataError> ErrorPage = null;
        DownDataErrorExample example = new DownDataErrorExample();
        DownDataErrorExample.Criteria criteria = example.createCriteria();
        criteria.andDelStateEqualTo(0L);

        for (int i = 1; i <= countPage; i++) {
            ErrorPage = downDataErrorService.selectByExample(example, i);
            if (null == ErrorPage.getList() || ErrorPage.getList().size() <= 0) {
                break;
            }
            for (DownDataError downDataError : ErrorPage.getList()) {
                String caseId = downDataErrorService.invokeErrorInfo(downDataError);
                if (StringUtils.isNotEmpty(caseId)) {
                    System.out.println("处理错误数据_修改CaseID为:" + caseId);
                    //cgaCaseService.updateIsPrecityToNull(caseId);

                    CgaCase cgaCase = cgaCaseService.selectOneByCaseId(caseId);
                    if (null != cgaCase) {
                        synchronousPreCity.synchronousMethos(cgaCase);
                    }
                }
            }
            countTotal = ErrorPage.getTotal();
            Integer MycountPage = ErrorPage.getPages();
            if (MycountPage >= countPage) {
                countPage = MycountPage;
            } else {
                i--;
            }
        }
        upDataReconciliationService.countdataByCDbatch();
        System.out.println("处理错误数据完成");
    }
}
